#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 20, M = 1e5;

int n, m;
map<string, int> mp;
string s[8], str;
bool st[8];
bool flag;



void dfs(int len, bool used, string cur, int nums){

    if(flag) return;

    if(nums == n){

        if(cur.length() < 3 || cur.length() > 16) return;
        if(!mp.count(cur)){
            flag = true;
            cout << cur << endl;
        }
        return;
    }

    if(nums >= 1 && !used){
        if(len + 1 > 16){
            return;
        }else{
            len ++;
            cur += "_";
            used = true;
        }
    }

    if(nums >= 1 && len + 1 <= 16){
        dfs(len + 1, used, cur + "_", nums);
    }

    for(int i = 0; i < n; i ++){
        if(!st[i]){
            if(len + s[i].length() > 16) return;
            st[i] = true;
            dfs(len + s[i].length(), false, cur + s[i], nums + 1);
            st[i] = false;
        }
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    flag = false;
    cin >> n >> m;
    for(int i = 0; i < n; i ++){
        cin >> s[i];
    }

    for(int i = 0; i < m; i ++){
        cin >> str;
        mp[str] = 1;
    }


    dfs(0, false, "", 0);
    if(!flag) cout << -1 << endl;

    return 0;
}